package com.feihao.zhou.ThreadSaveDemo3;

public class Cooker implements Runnable {
    private Desk desk;

    public Cooker(Desk desk) {
        this.desk = desk;
    }

    @Override
    public void run() {
        while (true){
            synchronized (desk){
                if (desk.getCount()==0){//包子制作10次数完了
                    break;
                }
                if (!desk.isFlag()){//如果没有包子
                    System.out.println("厨师正在做包子");
                    desk.setFlag(true);
                    desk.notify();//叫醒吃货
                }else {
                    try {
                        desk.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}








































    /*private Desk desk;

    public Cooker(Desk desk) {
        this.desk = desk;
    }

    @Override
    public void run() {
        while (true){
            synchronized (desk.getLock()){
                if (desk.getCount() == 0){
                    break;
                }else {
                    if (!desk.isFlag()){//如果没有
                        System.out.println("厨师正在做包子。");
                        desk.setFlag(true);
                        desk.getLock().notify();
                    }else {
                        try {
                            desk.getLock().wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
    }
}
*/